from collections import defaultdict

b = """
one
five
nine
"""


class Solution:
    def originalDigits(self, s: str) -> str:
        mid_dic = defaultdict(int)
        res_list = [0] * 10
        for alpha in s:
            mid_dic[alpha] += 1

        res_list[0] = mid_dic["z"]
        mid_dic["e"] -= mid_dic["z"]
        mid_dic["r"] -= mid_dic["z"]
        mid_dic["o"] -= mid_dic["z"]

        res_list[2] = mid_dic["w"]
        mid_dic["t"] -= mid_dic["w"]
        mid_dic["o"] -= mid_dic["w"]

        res_list[4] = mid_dic["u"]
        mid_dic["f"] -= mid_dic["u"]
        mid_dic["o"] -= mid_dic["u"]
        mid_dic["r"] -= mid_dic["u"]

        res_list[6] = mid_dic["x"]
        mid_dic["s"] -= mid_dic["x"]
        mid_dic["i"] -= mid_dic["x"]

        res_list[8] = mid_dic["g"]
        mid_dic["e"] -= mid_dic["g"]
        mid_dic["i"] -= mid_dic["g"]
        mid_dic["h"] -= mid_dic["g"]
        mid_dic["t"] -= mid_dic["g"]

        res_list[3] = mid_dic["t"]
        mid_dic["e"] -= 2 * mid_dic["t"]

        res_list[7] = mid_dic["s"]
        mid_dic["e"] -= 2 * mid_dic["s"]
        mid_dic["v"] -= mid_dic["s"]
        mid_dic["n"] -= mid_dic["s"]

        res_list[5] = mid_dic["f"]
        res_list[1] = mid_dic["o"]
        res_list[9] = (mid_dic["n"] - mid_dic["o"]) // 2

        res = ""
        for i in range(10):
            if res_list[i]:
                res += (str(i) * res_list[i])
        return res


a = Solution()
print(a.originalDigits(b))
print(a.originalDigits("owoztneoer"))
print(a.originalDigits("fviefuro"))
print(a.originalDigits("ereht"))
print(a.originalDigits("esnve"))
print(a.originalDigits("zerozero"))
